package client.superadmin;

import static org.stjs.javascript.JSCollections.$array;
import static org.stjs.javascript.JSCollections.$map;

import org.stjs.javascript.Array;
import org.stjs.javascript.Map;

import client.common.EndPoints.SupadminEP;
import client.common.Models.Grado;
import client.common.angular.NgScope;
import client.common.angular.UIState;
import client.common.directives.EPModal;
import client.common.javascript.JsProcedure1;

public class ColGradosScope extends NgScope {
	public static Array<String> $inject() {
		return $array("$state", "$stateParams", "Superadmin", "epModal");
	}

	private Long idColegio;
	private Array<Grado> grados;
	private Grado nuevoGrado;
	private SupadminEP superEP;
	private EPModal epModal;
	private UIState state;

	public ColGradosScope(UIState state, Map<String, Long> stateParams,
			SupadminEP superEP, EPModal epModal) {
		super("ColGradosScope");
		idColegio = stateParams.$get("idColegio");

		grados = superEP.getGradosColegio(idColegio);
		this.superEP = superEP;
		this.epModal = epModal;
		this.state = state;

	}

	public void crearGrado() {
		final ColGradosScope self = this;
		nuevoGrado.idColegio = idColegio;
		superEP.newGradoColegio(nuevoGrado, new JsProcedure1<Grado>() {

			@Override
			public void $invoke(Grado p) {
				self.grados.push(p);
				self.epModal.close("nuevo-grado");
				self.nuevoGrado = new Grado();
			}
		});
	}

	public void verGrado(Grado grado) {
		state.transitionTo("colegio.ofertaAcademica.grado",
				$map("idColegio", idColegio, "idGrado", grado.id));
	}
}
